<template>
	<view class="content">
		<view class="header">
			<view class="ipt-box">
				<input v-model="number" type="text" value="" placeholder="请输入隐患编号" placeholder-class="plac-class" />
				<image src="/static/search1.png" mode="" @click="searchList"></image>
			</view>
			<view class="header-right">
				<easy-select class="easySelect" style="width:360rpx;height:100%;font-size: 28rpx;color: #fff;" :options="options" ref="easySelect" size="medium" :value="selecValue" @selectOne="selectOne"></easy-select>
			</view>
		</view>
	 
		<!-- nav -->
		<view class="nav">
			<view class="nav-box">
				<span :class="{'current' :active===1}" @click="navClick(0)">我上传的隐患</span>
				<span :class="{'current' :active===2}" @click="navClick(1)">所有隐患</span>
			</view>
		</view>
		<!-- danger -->
		<view class="danger-box">
			<view class="danger-item" v-for="(item,index) in dangerList" :key="index" @tap="checkDanger(item.id)">
				<view class="safe"> <image src="/static/aqy.png" mode=""></image>{{item.role_name}}</view>
				<view>隐患编号：{{item.no}}</view>
				<view>上传日期：{{item.create_time}}</view>
				<view>隐患地址：{{item.address}}</view>
				<view>状<text class="kong"></text>态：{{item.status_msg}}</view>
				<text class="chaoshi_zhuantai">{{item.exceed_time == false ? '' : '已超时'}}</text>
				<!-- <image class="shenhe" :src="item.status_picture" mode=""></image> -->
			</view>
			<view class="nomodel" v-if="dangerList.length==0">
				<u-empty  text="暂无隐患"  mode="list"></u-empty>
			</view>
			 
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				username: '',
				password: '',
				// array: ['安装工','检测工','维修工'],
				index: 0,
				userinfo:{},
				value:'',  //搜索关键词
				installList:[],  //安装列表
				dosearch:false,
				showAcount:false,
				page:1,
				dangerList:[],
				active:1,
				trackFlag: false,
				trackName: 0,
				 selecValue: '',
				 options: [],
				 number:'',
				 totwn:''
			};
		},
		onLoad() {
			this.userinfo=this.user
			// this.getInstallDetail()
		},
		onShow() {
			uni.getStorage({
				key: 'token'
			}).then(da => {
				this.token = da[1].data
				this.getInstallDetail()
				this.getList()
			})
			 
		},
		//下拉刷新
		onPullDownRefresh(){
			this.page=1
			 setTimeout(function() {
			 	uni.stopPullDownRefresh();
			 }, 500);
			this.getInstallDetail()
		},
		onReachBottom() {
			if(this.page >= this.totwn) {
				uni.showToast({
					title: '没有更多数据',
					icon: 'none'
				})
				return
			}else{
				this.page++
				this.getInstallDetail()
			}
			
		},
		methods: {
			selectOne(option) {
				console.log(option)
				this.dangerList = []
				this.selecValue = option.label
				this.trackName = option.id;
				
				this.getInstallDetail()
			},
			checkDanger(id){
				uni.navigateTo({
					url:'./dangerFollow?id=' + id
					// url:'dangerFollow?id=' + id
				})
			},
			async getList() {
				let that = this
				const res = await that.$request.request({
					url: 'common/danger_type',
					method: 'POST',
					data: {
						token: that.token
					}
				})
				that.options = res.data.data
				if(that.options){
					this.selecValue = that.options[0].label
				}
			},
			navClick(i){
				this.page=1
				this.dangerList = []
				this.active = i + 1
				this.getInstallDetail()
			},
			searchList() {
				if(this.number == '') {
					uni.showToast({
						title: '请输入编号查找',
						icon: 'none'
					})
					this.getInstallDetail()
					return
				}else{
					this.getInstallDetail()
				}
			},
			searchFocus(){
				this.showAcount=false
			},
			infoClick(){
				this.showAcount=!this.showAcount
			},
			// 跳转至记录页面
			toJiLu(){
				uni.navigateTo({
					url:'./jilu'
				})
			},
			// 跳转用户信息页面
			toCaiLiao(id){
				uni.navigateTo({
					url:'../userinfo/uninstall?id='+id
				})
			},
			// 点击获取安装数据
			searchUser(val){
				// this.getInstallDetail ()
				this.dosearch=true
				uni.navigateTo({
					url:'../query/query?key='+val
				})
			},
			// 获取安装数据
			getInstallDetail () {
				let that = this
				// uni.showLoading({uni.hideLoading()
				// 	title:'查询中'
				// })
				that.$request.request({
					url: '/danger/danger_list',
					method: 'POST',
					data: {
						page: that.page,
						status: that.trackName,
						type: that.active,
						token: that.token,
						no: that.number
					}
				}).then(res => {
					if(res.data.code == 1) {
						that.totwn = res.data.data.page_count
						that.dangerList =that.dangerList.concat(res.data.data.data_info)
						
					}else {
						uni.showToast({
							title: '没有更多数据',
							icon: 'none'
						})
						that.number = ''
						return
					}
				})
			 },
		},
		
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #F5F5F5;
		// padding-bottom: 200rpx;
		// margin-bottom: 150rpx;
	}
	.nomodel{
		margin-top: 60rpx;
	}
	.content{
		padding-bottom: 140rpx;
	}
	.header{
		display: flex;
		justify-content: space-between;
		align-items: center;
		box-sizing: border-box;
		height: 80rpx;
		width: 100%;
		background-color: #003690;
		padding: 0 40rpx;
		.ipt-box{
			display: flex;
			justify-content: space-between;
			align-items: center;
			box-sizing: border-box;
			padding: 0 20rpx;
			width:500rpx;
			height: 52rpx;
			background-color: #fff;
			border-radius: 24rpx;
			input{
				width: 85%;
			}
			image{
				width: 32rpx;
				height: 32rpx;
			}
		}
		.header-right{
			display: flex;
			align-items: center;
			font-size: 32rpx;
			color: #E2ECFB;
			position: relative;
			width: 200rpx;
			image{
				width: 36rpx;
				height: 36rpx;
			}
			.genFle{
				position: absolute;
				top: 64rpx;
				left: 0;
				width: 100%;
				background-color: #fff;
				border: 2rpx solid #ccc;
				color: #003690;
				text-align: center;
				z-index: 999;
				view{
					border-bottom: 2rpx solid #ccc;
					line-height: 60rpx;
				}
			}
		}
	}
	.test-code:active{
		background: rgba(69, 82, 202, 0.4);
		color: #fff;
	}
	.plac-class{
		font-size: 32rpx;
		color: #999;
	}
	// nav
	.nav{
		width: 100%;
		height: 80rpx;
		background-color: #fff;
		.nav-box{
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 50%;
			margin: 0 auto;
			line-height: 76rpx;
			span{
				padding: 0 10rpx;
				font-size: 32rpx;
				color: #333;
				border-bottom: 4rpx solid transparent;
			}
			.current{
				color: #003690;
				border-bottom: 4rpx solid #003690;
			}
		}
	}
	// danger
	.danger-item{
		position: relative;
		box-sizing: border-box;
		width: 690rpx;
		padding: 30rpx;
		background-color: #fff;
		border-radius: 10rpx;
		margin: 30rpx auto 0;
		box-shadow:0px 3px 4px rgba(0,30,57,0.15);
		.safe{
			color: #003690;
			font-size: 28rpx;
			line-height: 38rpx;
			image{
				width: 36rpx;
				height: 36rpx;
				margin-right: 6rpx;
				vertical-align: bottom;
			}
		}
		.kong{
			display: inline-block;
			width: 56rpx;
		}
		.kong1{
			display: inline-block;
			width: 14rpx;
		}
		.chaoshi_zhuantai{
			position: absolute;
			top: 20rpx;
			right: 20rpx;
			color: red;
			font-size: 28rpx;
			line-height: 38rpx;
		}
		.shenhe{
			position: absolute;
			top: 100rpx;
			right: 20rpx;
			width: 170rpx;
			height: 170rpx;
		}
	}
</style>
